<?php
/**
 * @package RSS STOK
 * @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * RSS STOK! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */

// no direct access
defined( '_VALID_MOS' ) or die();

/**
* @package Joomla
* @subpackage Syndicate
*/
class HtmlRdRss {

	function show($option, $task, $rows, $pageNav, $search){
		global $my;

		$cur_file_icons_path = JPATH_SITE.'/'.ADMINISTRATOR_DIRECTORY.'/templates/'.JTEMPLATE.'/images/ico/';

		mosCommonHTML::loadOverlib();
		?>
		<form action="index2.php" method="post" name="adminForm">

		<table class="adminheading">
		<tr><th class="rss" rowspan="2"><?php echo _RSSST_ITEM ?></th>
		<td colspan="2" align="right"></td></tr>
		<tr><td><?php echo _RSSST_FILTER ?>:</td><td> <input type="text" name="search" value="<?php echo $search ?>" class="text_area" onChange="document.adminForm.submit();" />
		</td></tr></table>

		<table width="100%" class="adminlist"><tr>
			<th width="5"><input type="checkbox" name="toggle" value="" onClick="checkAll(<?php echo count( $rows ) ?>);" /></th>
			<th class="title" ><?php echo _RSSST_NAME;?></th>
			<th align="center" class="title" ><?php echo _RSSST_URL;?></th>
			<th class="title" ><?php echo _PUBLISHED;?></th>
			<th ><?php echo _RSSST_ID;?></th>
		</tr>
<?php
		$k = 0;
		$f =count( $rows );
		for ($i=0, $n=$f; $i < $n; $i++) {
			$row = &$rows[$i];
			$checked = mosCommonHTML::CheckedOutProcessing( $row, $i );
			$link = 'index2.php?option='.$option.'&amp;task=edit&amp;hidemainmenu=1&amp;id='. $row->id;
			
			if ( $row->published ) {
				$img = 'publish_g.png';
				$alt = _PUBLISHED;
				$todo = 'unpublish';
			} else {
				$img = 'publish_x.png';
				$alt = _NOT_PUBLISHED;
				$todo = 'publish';
			}
			
		?>
		<tr class="row<?php echo $k ?>">
			<td><?php echo $checked; ?></td>
			<td>
			<?php
			if ( $row->checked_out && $row->checked_out != $my->id) {
				echo $row->name;
			} else {
				echo '<a href="' . $link. '" title="'.$row->name.'">';
				echo htmlspecialchars($row->name, ENT_QUOTES);
				echo "</a>";
			}
			?>
			</td>
			<td>
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>" target="_blank"><b>RSS 2.0</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=rss1.0" target="_blank"><b>RSS 1.0</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=rss0.91" target="_blank"><b>RSS 0.91</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=opml" target="_blank"><b>OPML</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=atom" target="_blank"><b>ATOM</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=atom0.3" target="_blank"><b>ATOM 0.3</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=html" target="_blank"><b>HTML</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=js" target="_blank"><b>JS</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=yandex" target="_blank"><b>Yandex.ru</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=meta" target="_blank"><b>Meta.ua</b></a> |
				<a href="<?php echo JPATH_SITE . '/index.php?option=com_rss_stok&amp;id='.$row->id ?>&amp;feed=rss2ex" target="_blank"><b><?php echo _RSSST_RSS20IMG ?></b></a> |
			</td>
			<td align="center" <?php echo ($row->checked_out && ($row->checked_out != $my->id)) ? null : 'onclick="ch_publ('.$row->id.',\'com_rss_stok\');" class="td-state"';?>>
				<img class="img-mini-state" src="<?php echo $cur_file_icons_path;?>/<?php echo $img;?>" id="img-pub-<?php echo $row->id;?>" alt="<?php echo _PUBLISHING?>" />
			</td>
			<td><?php echo $row->id;?></td>
			</tr>
			<?php $k = 1 - $k;
		}?>
		</table>
		<?php echo $pageNav->getListFooter();?>
		<input type="hidden" name="option" value="<?php echo $option ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="hidemainmenu" value="0" />
		</form>
<?php
	}
	
	
	function edit ($option,  $task, $id, $row, $params,$lists){
		mosCommonHTML::loadOverlib();

		?>
		<script language="javascript" type="text/javascript">
			function submitbutton(pressbutton) {
				var form = document.adminForm;
				if (pressbutton != '') {
					if (pressbutton == 'cancel') {
						submitform( pressbutton );
					} else {						
						// do field validation 
						if (form.name.value == ""){
							alert( "<?php echo _RSSST_ERRNAME ?>" );
						} else {
						submitform( pressbutton );
						}
					}
				}
			}
		</script>
	<form action="index2.php" method="post" name="adminForm" id="adminForm">
		<table class="adminheading">
			<tr>
				<th class="rss"><?php echo $row->id ? _CHANGE_CONTENT : _CREATION; echo ' '._RSSST_ITEM;?></th>
			</tr>
		</table>
		<table width="100%" class="adminform">
			<tr>
				<th width="40%" colspan="2"><?php echo _RSSST_SETTINGS;?></th>
				<th><?php echo _RSSST_PARAMETERS;?></th>
			</tr>
			<tr>
				<td valign="top" align="left" ><?php echo _NAME;?></td>
				<td valign="top"><input type="text" name="name" size="50" maxlength="255" value="<?php echo $row->name ?>" class="text_area" /></td>
				<td rowspan="3"><?php echo $params->render();?></td>
			</tr>
			<tr>
				<td valign="top" align="left"><?php echo _PUBLISHED;?></td>
				<td valign="top"><input type="checkbox" name="published" value="1" <?php echo $row->published ? 'checked="checked"' : '';?> /></td>
			</tr>
			<tr>
				<td valign="top" align="left"><?php echo _RSSST_CATEGORY;?> </td>
				<td valign="top"><?php echo $lists['catids'];?> </td>
			</tr>
		</table>
		<input type="hidden" name="created" value="<?php echo $row->created ?>" />
		<input type="hidden" name="created_by" value="<?php echo $row->created_by ?>" />
		<input type="hidden" name="modified" value="<?php echo $row->modified ?>" />
		<input type="hidden" name="modified_by" value="<?php echo $row->modified_by ?>" />
		<input type="hidden" name="id" value="<?php echo $row->id ?>" />
		<input type="hidden" name="option" value="<?php echo $option ?>" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
	</form>
<?php
	}
}